package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 套餐管里相关接口
 * @author: 韩汶锦
 * @date: 2025/4/3
 */
@Api(tags = "套餐管理相关接口")
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    private static final Logger log = LoggerFactory.getLogger(SetmealController.class);
    @Autowired
    private SetmealService setmealService;

    /**
     * @description: 分页查询
     * @author: 韩汶锦
     * @date: 2025年04月03日
     *  * @Param setmealPageQueryDTO
     *  * @Return com.sky.result.Result<com.sky.result.PageResult>
     **/
    @GetMapping("/page")
    @ApiOperation("分页查询套餐")
    public Result<PageResult> selectByPage(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("分页查询接收数据：{}",setmealPageQueryDTO);
        PageResult pageResult = setmealService.selectByPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 新增套餐
     * @author: 韩汶锦
     * @date: 2025年04月03日
     *  * @Param setmealDTO
     *  * @Return com.sky.result.Result
     **/
    @ApiOperation("新增套餐")
    @PostMapping
    @CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
    public Result save(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐数据{}",setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }
/**
 * @description: 根据id查询套餐
 * @author: 韩汶锦
 * @date: 2025年04月03日
 *  * @Param id
 *  * @Return com.sky.result.Result
 **/
    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.selectById(id);
        return Result.success(setmealVO);
    }

    /**
     * @description: 修改套餐
     * @author: 韩汶锦
     * @date: 2025年04月03日
     *  * @Param setmealDTO
     *  * @Return com.sky.result.Result
     **/

    @ApiOperation("修改套餐")
    @PutMapping
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public  Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改元素值{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }
    /**
     * @description: 修改套餐状态
     * @author: 韩汶锦
     * @date: 2025年04月03日
     *  * @Param status
     * @Param id
     *  * @Return com.sky.result.Result
     **/
    @ApiOperation("修改套餐状态")
    @PostMapping("/status/{status}")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result updateStatus(@PathVariable String status ,Long id){
        log.info("修改状态接收参数{}，{}",status,id);
        setmealService.updateStatus(id,status);
        return Result.success();
    }
    /**
     * @description: 批量删除套餐
     * @author: 韩汶锦
     * @date: 2025年04月03日
     *  * @Param ids
     *  * @Return com.sky.result.Result
     **/
    @ApiOperation("批量删除套餐")
    @DeleteMapping
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result delete(String ids){
        log.info("查看批量删除套餐接收参数{}",ids);
        setmealService.delete(ids);
        return Result.success();
    }
}

